Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 4x 4x 4x 4x 4x 1x 3x 3x 2x 1x 1x | import { NextRequest, NextResponse } from "next/server";
import { edcClient } from "@/lib/edc";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
import { isPlainId } from "@/lib/transfer-data";
import { toAgreementView } from "@/lib/agreement";
export const dynamic = "force-dynamic";
/**
* GET /api/agreements/[id]?participantId=<ctx> — one contract agreement from
* the connector: when it was signed, until when it allows use, and the policy
* both parties agreed to (#876). The transfer page shows it beside the data.
*/
export async function GET(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const auth = await requireAuth();
Iif (isAuthError(auth)) return auth;
const { id } = await params;
const participantId = req.nextUrl.searchParams.get("participantId") || "";
if (!isPlainId(participantId) || !isPlainId(id)) {
return NextResponse.json(
{ error: "participantId and an agreement id are required" },
{ status: 400 },
);
}
try {
const raw = await edcClient.management<Record<string, unknown>>(
`/v5/participants/${participantId}/contractagreements/${id}`,
);
return NextResponse.json(toAgreementView(raw));
} catch (err) {
console.error(`Agreement ${id} not readable:`, err);
return NextResponse.json(
{ error: "Not found", detail: "The connector has no such agreement" },
{ status: 404 },
);
}
}
|